home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 627 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.6 KB

  1. Path: bart.crd.ge.com!volpe
  2. From: volpe@bart.crd.ge.com (Christopher R. Volpe)
  3. Newsgroups: comp.std.c
  4. Subject: Re: Restrictions on qsort compare function?
  5. Date: 22 Mar 1996 16:29:32 GMT
  6. Organization: GE Corporate Research & Development
  7. Sender: volpe@bart (Christopher R. Volpe)
  8. Distribution: world
  9. Message-ID: <4iukhc$5nr@rdsunx.crd.ge.com>
  10. References: <4iokop$h4p@lyra.csx.cam.ac.uk> <4iqjar$2m9@usenet.pa.dec.com> <1996Mar21.113301.2622@sq.com> <4it51b$ng8@usenet.pa.dec.com>
  11. Reply-To: volpe@ausable.crd.ge.com
  12. NNTP-Posting-Host: bart.crd.ge.com
  13.  
  14. In article <4it51b$ng8@usenet.pa.dec.com>, diamond@tbj.dec.com (Norman Diamond) writes:
  15. |>
  16. |>>>Just one sentence earlier, you gave the exact reason why
  17. |>>>it doesn't matter if you do "a > b" instead of "a - b".
  18. |>
  19. |>>Of course it matters.  With this function, if compar(x,y) > 0, then
  20. |>>compar(y,x) == 0.  This is not antisymmetric.
  21. |>
  22. |>Argh!  I was remembering what the hardware usually does for comparison
  23. |>instructions, and forgot that C operators lose part of that information.
  24. |>I must be getting Cnile.
  25. |>
  26. |>>(a > b)? 1: (a < b)? -1: 0
  27. |>
  28. |>Yup.  Incidentally, do you think the average implementation's
  29. |>interprocedural optimization phase will change this user function into
  30. |>one machine instruction in the library's qsort() function :-?
  31.  
  32. I'd be quite impressed if it did.
  33.  
  34. Alternatively, how about this:
  35.  
  36.     return ((signed int) ((unsigned int)a - (unsigned int)b));
  37.  
  38. --
  39.  
  40. Chris Volpe                Phone: (518) 387-7766 (Dial Comm 8*833
  41. GE Corporate R&D            Fax:   (518) 387-6560
  42. PO Box 8, Schenectady, NY 12301        Email: volpecr@crd.ge.com
  43.  
  44.